import os


def rename(dir_path):
    # 获取类别
    class_name_list = os.listdir(dir_path)
    # 遍历类别
    for class_name in class_name_list:
        # 获取所有图片
        img_list = os.listdir(dir_path + class_name)
        # 遍历图片
        for i in range(len(img_list)):
            # 重命名为类别+数字的规范化名称
            os.rename(dir_path + class_name + '/' + img_list[i],
                      dir_path + class_name + '/' + class_name + str(i) + '.jpg')


rename('train/')
rename('val/')
